<?php
/* Copyright (C) 2007-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
 * Copyright (C) ---Put here your own copyright and developer email---
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 *   	\file       dev/skeletons/skeleton_page.php
 *		\ingroup    mymodule othermodule1 othermodule2
 *		\brief      This file is an example of a php page
 *					Put here some comments
 */

//if (! defined('NOREQUIREUSER'))  define('NOREQUIREUSER','1');
//if (! defined('NOREQUIREDB'))    define('NOREQUIREDB','1');
//if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
//if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
//if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');	// If there is no menu to show
//if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');	// If we don't need to load the html.form.class.php
//if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
//if (! defined("NOLOGIN"))        define("NOLOGIN",'1');		// If this page is public (can be called outside logged session)

// Change this following line to use the correct relative path (../, ../../, etc)
$res=0;
if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php';
if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php';
if (! $res && file_exists("../../../main.inc.php")) $res=@include '../../../main.inc.php';
if (! $res && file_exists("../../../doli/htdocs/main.inc.php")) $res=@include '../../../doli/htdocs/main.inc.php';     // Used on dev env only
if (! $res && file_exists("../../../../doli/htdocs/main.inc.php")) $res=@include '../../../../doli/htdocs/main.inc.php';   // Used on dev env only
if (! $res && file_exists("../../../../../doli/htdocs/main.inc.php")) $res=@include '../../../../../doli/htdocs/main.inc.php';   // Used on dev env only
if (! $res) die("Include of main fails");
// Change this following line to use the correct relative path from htdocs
dol_include_once('/bir/class/assets.class.php');

// Load traductions files requiredby by page
$langs->load("companies");
$langs->load("other");

// Get parameters
$id         = GETPOST('asset_id','int');
$assets = new Assets($db);

/***************************************************
* VIEW
*
* Put here all code to build page
****************************************************/

function depreciate($percentage, $assets){
    $table = '';
    $value = $assets->value;
    $depreciation = 0;
    
    for($i = 0; $i<=$assets->timeofuse; $i++){        
        $table .= '<tr><td>'.($assets->year+$i).'</td>'.
                  '<td>'.$depreciation.' &euro;</td><td>'.$value.' &euro;</td></tr>';
        
        $depreciation = round($value*($percentage),2);
        $value -= $depreciation;
    }
    return $table;
}


llxHeader('','Abschreibung Id: '.$id,'');

$form=new Form($db);

if(is_numeric($id) && $assets->fetch($id)){
?>
<h1>Abschreibung <?php echo $assets->name ?></h1>
    <table class="noborder">
    <tbody>
    <tr class="liste_titre">
        <td>Jahr</td>
        <td>Abschreibungsbetrag</td>
        <td>Restbuchwert</td>
    </tr>
    <?php
    echo depreciate(0.2, $assets);
    ?>
    </tbody>
    </table>
<?php           
        
} else {
    print 'Die ID konnte nicht zugeordnet werden.';
}
/*
?>
<h3>Neues Anlagevermögen anlegen</h3>
<form action="" method="post">
    <table>
        <tr>
            <td><label for="asset_name">Name:</label></td>
            <td><input type="text" id="asset_name" name="asset_name" /></td>
        </tr>
        <tr>
            <td><label for="asset_name">Anschaffungsjahr:</label></td>
            <td><input type="text" id="asset_year" name="asset_year" /></td>
        </tr>
        <tr>
            <td><label for="asset_value">Anschaffungswert:</label></td>
            <td><input type="text" id="asset_value" name="asset_value" /></td>
        </tr>
        <tr>
            <td><label for="asset_timeofuse">Nutzungsdauer:</label></td>
            <td><input type="text" id="asset_timeofuse" name="asset_timeofuse" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" value="anlegen" /></td>
        </tr>
    </table>
    <input type="hidden" name="action" value="add" />
</form>
<h3>Anlagevermögen</h3>
<table class="noborder">
    <tbody>
<tr class="liste_titre">
    <td>Nummer</td>
    <td>Name</td>
    <td>Wert</td>
    <td>Jahr</td>
    <td>Nutzungsdauer</td>
    <td></td>
    <td></td>
</tr>
<?php

$assets = new Assets($db);
$results = $assets->fetchAll();
if(is_array($results)){
        foreach($results as $result){
            ?>
            <tr>
                <td><?php echo $result->rowid ?></td>
                <td><?php echo $result->name ?></td>
                <td><?php echo $result->value ?></td>
                <td><?php echo $result->year ?></td>
                <td><?php echo $result->timeofuse ?></td>
                <td>
                    <form action="" method="post">
                        <input type="submit" value="löschen" />
                        <input type="hidden" name="asset_id" value="<?php echo $result->rowid ?>" />
                        <input type="hidden" name="action" value="delete" />
                    </form>
                </td>
                <td>
                    <form action="" method="post">
                        <input type="submit" value="Abschreibung anzeigen" />
                        <input type="hidden" name="asset_id" value="<?php echo $result->rowid ?>" />
                        <input type="hidden" name="action" value="showDepriciation" />
                    </form>
                </td>
            </tr>

            <?php    
        }
} else {
    ?>
            <tr>
                <td colspan="7">
                    Kein Anlagevermögen vorhanden.
                </td>
            </tr>

            <?php 
}
?>
    </tbody>
</table>
<?php
 * 
 */



// End of page
llxFooter();
$db->close();
?>
